Imports MIMS.WRS.Business
Imports MIMS.WRS.Entities

Public Class ContainerDeliveredReport
    Inherits System.Web.UI.Page

    Protected WithEvents dtFromDate As DateTimePicker
    Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
    Protected WithEvents dtToDate As DateTimePicker

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents rptList As System.Web.UI.WebControls.Repeater

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected Function GetPrimaryText(ByVal data As Object) As String
        If data Is DBNull.Value OrElse Convert.ToString(data).Trim().Length = 0 Then
            Return "&nbsp;"
        Else
            Return Utilities.GetPrimaryMeaning(Convert.ToString(data))
        End If
    End Function

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            Dim fromDate As DateTime = Nulls.NullDate
            Try
                fromDate = DateTime.Parse(Request.QueryString("fromDate"))
            Catch ex As Exception
            End Try
            If Not fromDate.Equals(New Date(1900, 1, 1)) Then
                dtFromDate.SelectedValue = fromDate
            End If

            Dim toDate As DateTime = Nulls.NullDate
            Try
                toDate = DateTime.Parse(Request.QueryString("toDate"))
            Catch ex As Exception
            End Try
            If Not toDate.Equals(New Date(2999, 1, 1)) Then
                dtToDate.SelectedValue = toDate
            End If

            If fromDate = Nulls.NullDate Then
                fromDate = New Date(1900, 1, 1)
            End If

            If toDate = Nulls.NullDate Then
                toDate = New Date(2999, 1, 1)
            End If

            fromDate = New Date(fromDate.Year, fromDate.Month, fromDate.Day, 0, 0, 0)
            toDate = New Date(toDate.Year, toDate.Month, toDate.Day, 23, 59, 59)

            Me.rptList.DataSource = ShippingStatusReportService.GetContainerDeliveredReport(RequestContext.CurrentUser.ActiveOfficeID, fromDate, toDate, RequestContext.ReportType)
            Me.rptList.DataBind()
        End If
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim fromDate As DateTime = dtFromDate.SelectedValue
        Dim toDate As DateTime = dtToDate.SelectedValue

        If fromDate = Nulls.NullDate Then
            fromDate = New Date(1900, 1, 1)
        End If

        If toDate = Nulls.NullDate Then
            toDate = New Date(2999, 1, 1)
        End If

        Response.Redirect(String.Format("ContainerDeliveredReport.aspx?rt={0}&fromDate={1}&toDate={2}", _
                RequestContext.ReportType, fromDate.ToShortDateString, toDate.ToShortDateString))
    End Sub
End Class
